package com.tavenli.services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tavenli.entity.DeviceLogEntity;
import com.tavenli.entity.PersonEntity;
import com.tavenli.model.PageData;
import com.tavenli.repository.DeviceCmdDao;
import com.tavenli.repository.DeviceLogDao;

@Service
public class DeviceLogService {
	private static Logger logger = LoggerFactory
			.getLogger(UCenterService.class);
	
	@Autowired
	private DeviceLogDao deviceLogDao;
	public PageData<DeviceLogEntity> getDeviceLogList(Integer pageIndex,
			int pageSize, String personName) {
		PageData<DeviceLogEntity> pageData = new PageData<DeviceLogEntity>(pageIndex, pageSize);
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("personName", personName);
		int totalCount = deviceLogDao.queryDataCount(paramMap);
		List<DeviceLogEntity> list = deviceLogDao.queryPageData(pageData.getStartRow(), pageSize,paramMap);
		pageData.setTotalCount(totalCount);
		pageData.setPageData(list);
		return pageData;
	}
	
	@Transactional
	public void save(DeviceLogEntity deviceLogEntity) throws Exception {
		if(!deviceLogDao.exist(deviceLogEntity))
			this.deviceLogDao.saveAndRet(deviceLogEntity);
	}
	
	
}
